﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Code4Public.Settings;

namespace Code4Public.ThemeDesigners
{
    [DefaultEvent("LineNumbersThemeChanged")]
    public partial class ThemeLineNumbersDesigner : UserControl
    {
        public ThemeLineNumbersDesigner()
        {
            InitializeComponent();
        }

        private bool eventSuspended = false;

        public void SuspendEventRaising()
        {
            eventSuspended = true;
            this.lineNumbersFontDesigner.SuspendEventRaising();
        }

        public void ResumeEventRaising()
        {
            eventSuspended = false;
            this.lineNumbersFontDesigner.ResumeEventRaising();
        }

        public event EventHandler LineNumbersThemeChanged;

        private void lineNumbersFontDesigner_FontPropertiesChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void colorPickerLineNumbersBackColor_ColorChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void cbShowSeparatorLine_CheckedChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void colorPickerSeparatorLineColor_ColorChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void cbShowZeros_CheckedChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void cbShowStringAfterNumber_CheckedChanged(object sender, EventArgs e)
        {
            txtStringAfterNumber.Enabled = cbShowStringAfterNumber.Checked;

            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void nudSpacesBeforeNumber_ValueChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void nudSpacesAfterNumber_ValueChanged(object sender, EventArgs e)
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void OnStringAfterTextChanged()
        {
            if (!eventSuspended && LineNumbersThemeChanged != null)
                LineNumbersThemeChanged(this, new EventArgs());
        }

        private void txtStringAfterNumber_Leave(object sender, EventArgs e)
        {
            OnStringAfterTextChanged();
        }

        private void txtStringAfterNumber_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                OnStringAfterTextChanged();
        }

        public bool LineNumbersShowSeperatorLine
        {
            get
            {
                return cbShowSeparatorLine.Checked;
            }

            set
            {
                cbShowSeparatorLine.Checked = value;
            }
        }

        public Color LineNumbersSeperatorLineColor
        {
            get
            {
                return this.colorPickerSeparatorLineColor.Color;
            }

            set
            {
                this.colorPickerSeparatorLineColor.Color = value;
            }
        }

        public FontInfo LineNumbersFont
        {
            get
            {
                return new FontInfo(
                    this.lineNumbersFontDesigner.FontColor,
                    this.lineNumbersFontDesigner.FontBold,
                    this.lineNumbersFontDesigner.FontItalic);
            }

            set
            {
                this.lineNumbersFontDesigner.FontColor = value.Color;
                this.lineNumbersFontDesigner.FontBold = value.Bold;
                this.lineNumbersFontDesigner.FontItalic = value.Italic;
            }
        }

        public Color LineNumbersBackColor
        {
            get
            {
                return this.colorPickerLineNumbersBackColor.Color;
            }

            set
            {
                this.colorPickerLineNumbersBackColor.Color = value;
            }
        }

        public bool LineNumbersShowZeros
        {
            get
            {
                return cbShowZeros.Checked;
            }

            set
            {
                cbShowZeros.Checked = value;
            }
        }

        public bool LineNumbersShowStringAfter
        {
            get
            {
                return cbShowStringAfterNumber.Checked;
            }

            set
            {
                cbShowStringAfterNumber.Checked = value;
            }
        }

        public string LineNumbersStringAfter
        { 
            get 
            { 
                return txtStringAfterNumber.Text; 
            }

            set
            {
                txtStringAfterNumber.Text = value;
            }
        }

        public int LineNumbersSpacesAfter 
        {
            get
            {
                return (int)nudSpacesAfterNumber.Value;
            }

            set
            {
                nudSpacesAfterNumber.Value = value;
            }
        }

        public int LineNumbersSpacesBefore 
        {
            get
            {
                return (int)nudSpacesBeforeNumber.Value;
            }

            set
            {
                nudSpacesBeforeNumber.Value = value;
            }
        }





    }
}
